package platform

import (
	"errors"
)

var x86_64_SyscallMap = map[string]int{
	"5.18": 450,
	"5.15": 449,
	"5.10": 440,
	"4.19": 334,
	"4.18": 334,
}

var aarch64_SyscallMap = map[string]int{
	"5.18": 450,
	"5.15": 449,
	"5.10": 440,
	"4.19": 293,
	"4.18": 292,
}

func syncUpstream(arch string, kernnelVersion string) ([]string, error) {
	if arch != "amd64" && arch != "arm64" {
		return nil, errors.New("wrong architecture provided")
	}

	var result []string
	if arch == "amd64" {
		end, ok := x86_64_SyscallMap[kernnelVersion]
		if !ok {
			return nil, errors.New("wrong kernnelVersion provided")
		}

		for idx, syscall := range x86_64Syscalls {
			if idx <= end {
				result = append(result, syscall)
			}
		}
		return result, nil
	}

	end, ok := aarch64_SyscallMap[kernnelVersion]
	if !ok {
		return nil, errors.New("wrong kernnelVersion provided")
	}

	for idx, syscall := range x86_64Syscalls {
		if idx <= end {
			result = append(result, syscall)
		}
	}

	return result, nil
}
